package com.dongdongsongcan.app;

import android.text.TextUtils;

import com.baidu.location.BDLocation;
import com.dongdongsongcan.app.common.DDMessageDef;
import com.dongdongsongcan.app.common.DDSpKeysDef;
import com.dongdongsongcan.app.control.bean.DDLocation;
import com.dongdongsongcan.app.utils.LocationUtil;
import com.su.dolphin.DpApp;
import com.su.dolphin.core.notification.DpMessageCenter;
import com.su.dolphin.utils.DataStoreUtil;
import com.su.dolphin.utils.JSONUtil;
import com.su.dolphin.utils.StringUtil;

/**
 * Created by sfshine@qq.com on 2015/12/29 0029.
 */
public class DDApp extends DpApp {
    private static DDLocation sDDLocation;//搜索商铺的范围
    public static final String GET_LOCATION_ERR = "获取位置失败";

    @Override
    public void onCreate() {
        super.onCreate();
        sDDLocation = JSONUtil.parseObject(DataStoreUtil.i().getString(DDSpKeysDef.KEY_LOCATION, ""), DDLocation.class);
    }


    public static DDLocation getDDLocation() {
        if (sDDLocation == null || StringUtil.isNull(sDDLocation.getArea_name())) {
            sDDLocation = new DDLocation();
            sDDLocation.setArea_name(GET_LOCATION_ERR);
        }
        return sDDLocation;
    }

    public static void saveDDLocation(DDLocation ddLocaton) {
        sDDLocation = ddLocaton;
        String strDDlocation = JSONUtil.toJSONString(sDDLocation);
        DataStoreUtil.i().putString(DDSpKeysDef.KEY_LOCATION, strDDlocation);
        DpMessageCenter.i().notify(DDMessageDef.N_LOCATION_CHANGE);
    }
}
